Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ls method to list egg runing app #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

buzai
Copy link

@buzai buzai commented Sep 30, 2018

Description of change
pm2 ls

This command can output a table in the shell, list all the running app.

Egg-scripts does not have such a command, this commit add this command, can output a table to list the running egg app.

when install egg-scripts with global, just use
eg:

egg-scripts ls

can list all egg runing apps

It can add a title option to filter apps.
eg:

egg-scripts ls --title=xxxxx

This will filter the title include xxxx string apps.

Note: egg-scripts is not recommended to install global, you should install and use it as npm scripts. so can add it in npm scripts.

Most of the code is copied from the list function in pm2.

@buzai
Copy link
Author

buzai commented Sep 30, 2018

@fengmk2 pm2 code can use in egg?

lib/monitor.js Outdated

const pidusage = require('pidusage');

exports.getMonitorData = function getMonitorData(processs, cb) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use callback

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, now without callback

Copy link
Member

@popomore popomore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit test is required

const { argv } = context;
this.logger.info(`list egg application ${argv.title ? `with --title=${argv.title}` : ''}`);

const processList = yield this.helper.findNodeProcessWithPpid(item => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move the filter into findNodeProcessWithPpid.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@popomore This filter function use a title variable , so I think it's more appropriate to put it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this could extract to a utils function, and share with stop cmd

@codecov
Copy link

codecov bot commented Sep 30, 2018

Codecov Report

Merging #31 into master will decrease coverage by 41.85%.
The diff coverage is 10.11%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #31       +/-   ##
===========================================
- Coverage   99.51%   57.66%   -41.86%     
===========================================
  Files           6        9        +3     
  Lines         207      385      +178     
===========================================
+ Hits          206      222       +16     
- Misses          1      163      +162
Impacted Files Coverage Δ
index.js 100% <100%> (ø) ⬆️
lib/cmd/ls.js 15.38% <15.38%> (ø)
lib/helper.js 49.01% <18.75%> (-50.99%) ⬇️
lib/display.js 4.05% <4.05%> (ø)
lib/monitor.js 6.25% <6.25%> (ø)
lib/cmd/stop.js 93.33% <0%> (-6.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c2479dc...e3681ee. Read the comment docs.

const path = require('path');
const Command = require('../command');
const isWin = process.platform === 'win32';
const osRelated = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's duplication with stop cmd, extract this to helper or?

}

get description() {
return 'ls app';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list egg process

item.isAgent = false;
item.isWorker = false;

let tileFlag = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tileFlag -> titleFlag

const { argv } = context;
this.logger.info(`list egg application ${argv.title ? `with --title=${argv.title}` : ''}`);

const processList = yield this.helper.findNodeProcessWithPpid(item => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this could extract to a utils function, and share with stop cmd

}
return false;
});
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line

}


// get tile string in the script, tile as the project name ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title


exports.getMonitorData = function* getMonitorData(processs) {

return new Promise(function(resolve, reject) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer arrow style

return;
}

const pids = processs.map(pro => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const pids = processs.map(p => p.pid)

resolve(pids);
return;
}
pidusage(pids, function(err, statistics) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer arrow style

console.error('Error caught while calling pidusage');
console.error(err);

processs.map(function(pro) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer arrow style

@atian25
Copy link
Member

atian25 commented Oct 9, 2018

ping

@buzai
Copy link
Author

buzai commented Oct 10, 2018

@atian25 I’m a bit busy recently, I’ll try to fix the bug this month.

@atian25
Copy link
Member

atian25 commented Oct 10, 2018

没关系,有时间再改就行,不急。只是顺手 ping 下看看是不是哪里卡住了。

@@ -0,0 +1,145 @@
'use strict';
// code copy from pm2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PM2 是 AGPL 协议的,这里还是自己实现吧,不要复制,也不要参考太多。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants